package ${package};

import cn.sccl.common.model.PageResult;
import cn.sccl.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import ${modelClass};
import ${managerClass};

/**
* ${tableComments} 的Controller
* Created by ${author} on ${createDate}.
*/
@RestController
@RequestMapping(value = "${baseUrl}")
public class ${modelName}Controller extends BaseController {

@Autowired
private ${modelName}Manager ${modelName?uncap_first}Manager;

/**
* 显示所有数据
*/
@RequestMapping(value = "/all" , method = RequestMethod.GET)
public List<${modelName}> listAll${modelName}(){
return ${modelName?uncap_first}Manager.listAll();
}

/**
* 分页查询，分页参数放置在url路径中
* @param pageIndex 页码
* @param pageSize 分页大小
* @param request
* @return
*/
@RequestMapping(value = "/page/{pageIndex}/{pageSize}" , method = RequestMethod.GET)
public PageResult<${modelName}> pageQuery${modelName}(@PathVariable("pageIndex") long pageIndex , @PathVariable("pageSize") int pageSize , HttpServletRequest request){
return ${modelName?uncap_first}Manager.pageQueryByLike(pageIndex, pageSize, getQueryData(request));
}

/**
* 分页查询，分页参数放置在request中
* @param request
* @return
*/
@RequestMapping(value = "/page" , method = RequestMethod.GET )
public PageResult<${modelName}> pageQuery${modelName}(HttpServletRequest request){
return ${modelName?uncap_first}Manager.pageQueryByLike(getPageIndex(request), getPageSize(request), getQueryData(request));
}

/**
* 保存数据
* @param ${modelName?uncap_first}
* @return
*/
@RequestMapping(value = "/save" , method = RequestMethod.POST)
public ${modelName} save${modelName}(@RequestBody ${modelName} ${modelName?uncap_first}){
${modelName?uncap_first}Manager.save(${modelName?uncap_first});
return ${modelName?uncap_first};
}

/**
* 根据ID删除数据
* @param id
*/
@RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
@JsonView(Object.class)
public void delete${modelName}(@PathVariable("id") String id){
${modelName?uncap_first}Manager.delete(id);
}
}
